package com.cheng.example.book.java8actual.chapter03;

import lombok.Data;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/*
 * @author 程帅
 * @createTime: 2020/11/19 13:55
 * @Created: with IntelliJ IDEA.
 */
@Data
public class Weight implements Comparable<Weight> {

    private int num;

    private String unit;

    @Override
    public int compareTo(Weight w) {
        //按照重量排序
        return this.num - w.num;
    }

    /**
     * @param args
     */
    public static void main(String[] args) {
        Weight w1 = new Weight();
        w1.setNum(1);

        Weight w2 = new Weight();
        w2.setNum(3);

        Weight w3 = new Weight();
        w3.setNum(2);

        List<Weight> weightList = new ArrayList<>();
        weightList.add(w1);
        weightList.add(w2);
        weightList.add(w3);
        Collections.sort(weightList);
        System.out.println(weightList);
    }
}
